﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcAppDemo.Models.PaginatedList<MvcAppDemo.Models.Dinner>>" %>

<asp:Content ID="Title" ContentPlaceHolderID="TitleContent" runat="server">
    Upcoming Dinners
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="MainContent" runat="server">
    <div id="dinnerDiv">
        <h2>
            Upcoming Dinners</h2>
        <ul class="listview">
            <% foreach (var dinner in Model)
               { %>
            <li>
                <%=Html.ActionLink(dinner.Title, "Details", new { id=dinner.DinnerID }) %>
                on
                <%=Html.Encode(dinner.EventDate.ToShortDateString())%>
                @
                <%=Html.Encode(dinner.EventDate.ToShortTimeString())%>
            </li>
            <% } %>
        </ul>
        <div>
            <% if (Model.HasPreviousPage)
               { %>
            <%= Html.RouteLink("<<<", "UpcomingDinners", new { page = (Model.PageIndex-1) }) %>
            <% } %>
            <% if (Model.HasNextPage)
               {  %>
            <%= Html.RouteLink(">>>", "UpcomingDinners", new { page = (Model.PageIndex + 1) }) %>
            <% } %>
        </div>
        <div>
            <%=Html.ActionLink("Add", "Create", "Dinners")%></div>
        <div id="dinnerList">
        </div>
    </div>
    <div id="mapDiv">
        <div id="searchBox">
            Enter your location:
            <%=Html.TextBox("Location") %>
            <input id="search" type="submit" value="Search" />
        </div>
        <div id="theMap">
        </div>
        <div style="color: #999; position: relative; right: 0px; top: 0px;" id="divPos">
            经度：<label style="width: 120px;"><%=22.5.ToString("#,00.000000")%></label>&nbsp;纬度：<label
                style="width: 120px;"><%=114.ToString("#,00.000000")%></label></div>
    </div>
    <script type="text/javascript">
        $(document).ready(function () {
            var latitude = 22.5;
            var longitude = 114;
            if ((latitude == 0) || (longitude == 0))
                LoadMap();
            else
                LoadMap(latitude, longitude, mapLoaded);
            $("#Location").keypress(function (e) {
                if (e.keyCode == 13) {
                    if (jQuery.trim($("#Location").val()) == '') return;
                    else $("#search").click();
                }
            });
            $("#search").click(function (evt) {
                var where = jQuery.trim($("#Location").val());
                if (where.length < 1)
                    return;
                FindDinnersGivenLocation(where);
            });
        });
        function mapLoaded() {
            map.SetZoomLevel(13);
            map.AttachEvent("onclick", showClickPos);
        }
        function showClickPos(e) {
            var x = e.mapX;
            var y = e.mapY;
            pixel = new VEPixel(x, y);
            LL = map.PixelToLatLong(pixel);
            var lat = LL.Latitude;
            var lot = LL.Longitude;
            lat = Math.round(lat * 1000000) / 1000000;
            lot = Math.round(lot * 1000000) / 1000000;
            $("#divPos label").each(function (i) {
                if (i == 0) $(this).text(lat);
                else $(this).text(lot);
            });
        }
    </script>
</asp:Content>
